package com.psp.web.model;

import java.util.ArrayList;

public class ServiceCateTree {

	private String name;
	private int code;
	private int parentCode;
	private int searchCode;
	private ArrayList<ServiceCateTree> subServices = new ArrayList<ServiceCateTree>(); ;

	public ServiceCateTree(String name, int code, int parentCode, int searchCode) {
		this.name = name;
		this.code = code;
		this.parentCode = parentCode;
		this.searchCode = searchCode;
	}

	public void add(ServiceCateTree cate, int code) {// 递归添加节点
		if (cate.parentCode == 0) {
			this.subServices.add(cate);
		} else if (cate.parentCode == this.searchCode) {
			cate.setCode(code);
			this.subServices.add(cate);
		} else {
			int i = 1;
			for (ServiceCateTree tmp_node : subServices) {
				int num = i++;
				tmp_node.setCode(num);
				tmp_node.add(cate, num);
			}
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public int getSearchCode() {
		return searchCode;
	}

	public void setSearchCode(int searchCode) {
		this.searchCode = searchCode;
	}

	public ArrayList<ServiceCateTree> getSubServices() {
		return subServices;
	}

	public void setSubServices(ArrayList<ServiceCateTree> subServices) {
		this.subServices = subServices;
	}

	public int getParentCode() {
		return parentCode;
	}

	public void setParentCode(int parentCode) {
		this.parentCode = parentCode;
	}

	@Override
	public String toString() {
		return "ServiceCateTree [name=" + name + ", code=" + code + ", parentCode=" + parentCode + ", searchCode="
				+ searchCode + ", subServices=" + subServices + "]";
	}
	
	

}
